home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-07-22 | 9.1 KB | 283 lines | [TEXT/PJMM] |
- unit HelloTabby;
-
- { Written by Pete Johnson, Glassell Park BBS, 213-258-7649 }
-
- { Source for a LightSpeed Pascal unit which handles the Tabby launch.next }
- { file and returns the name of the next application to launch in a variable }
- { called NextLaunch. }
-
- { This source code is being made public in the hopes that it will lead to more }
- { and better Tabby applications. I ask only that you credit me with a thanks }
- { if you incorporate any or all of this code in an application. }
-
- { I have no doubt that this code could be made better. If you improve on it, }
- { please share your ideas. }
-
- { If you're not using LightSpeed Pascal, you're on your own. I don't know }
- { any other Pascal compilers. I'm sure someone other than me can help you }
- { if you need to convert this code for Turbo, TML or Apple's MPW Pascal. }
-
- { Thanks to Erik Selberg, who has been a real help. }
-
- { How to use this code: }
-
- { <1> Create a LightSpeed Pascal Project }
- { <2> Add the Globals.p file first, then add the HelloTabby.p file }
- { <3> Create your own additional files }
-
- { You should include an STR resource 500 in the Project: this holds the name }
- { of the default launch.next application (usually 'Red Ryder Host'). }
-
- { Your main program Unit should include the following lines at its start: }
-
- { uses }
- { Globals, HelloTabby; }
-
- { End the main procedure of your program as follows: }
-
- { HelloTabby; }
- { if NextLaunch <> '' then }
- { LaunchNextAppl }
- { end. }
-
-
- { ********** History ********** }
-
- { Modified March 11, 1989, to handle up to 100 events of < 32 chars apiece. }
- { Modified April 17 and May 6, 1989, to handle MultiFinder. }
- { Modified June 11, 1989, to use Toolbox file calls. }
- { Modified June 15, 1989, to use Tabby Setup name for 'BBS' string. }
- { Modified July 22, 1989, for additional error checking. }
-
- { Next four lines handle Debug, Names, Overflow and Range }
- { checking options in compiler. }
-
- {$D+}
- {$N+}
- {$V+}
- {$R+}
-
- interface
-
- uses
- Globals;
-
- type
- pLaunchStruct = ^LaunchStruct;
- LaunchStruct = record
- pfName: StringPtr;
- param: INTEGER;
- LC: packed array[0..1] of CHAR; { extended parameters: }
- extBlockLen: LONGINT; { number of bytes in extension = 6 }
- fFlags: INTEGER; { Finder file info flags }
- launchFlags: LONGINT; { bit 31,30=1 for sublaunch, others reserved }
- end; { LaunchStruct }
-
- var
- NextLaunch: STR255;
- MultiFinder: boolean;
-
- procedure LaunchNextAppl;
-
- procedure HelloTabby;
-
-
- implementation
-
- { ------------------------------------------------------ }
- procedure ReadConfig;
-
- var
- ConfigRefNum: integer;
- logicalEOF, CharsToSend: longint;
- MFByte: SignedByte;
-
- begin
- MultiFinder := false;
- CharsToSend := 1;
- FileError := FSOpen('Config', vRefNum, ConfigRefNum);
- if FileError = noErr then
- begin
- FileError := GetEOF(ConfigRefNum, logicalEOF);
- if (FileError = noErr) & (logicalEOF = 349) then
- begin
- FileError := SetFPos(ConfigRefNum, fsFromStart, 316);
- FileError := FSRead(ConfigRefNum, CharsToSend, @MFByte);
- if MFByte <> 0 then
- MultiFinder := true;
- end { if (FileError = noErr) & (logicalEOF = 349) }
- end; { if FileError = noErr }
- FileError := FSClose(ConfigRefNum);
- end;
-
- { ------------------------------------------------------ }
-
- function Launchit (pLnch: pLaunchStruct): OSErr;
-
- inline
- $205F, $A9F2, $3E80;
-
- { ------------------------------------------------------ }
-
- procedure LaunchNextAppl;
-
- var
- pMyLaunch: pLaunchStruct;
- myLaunch: LaunchStruct;
- MyPB: CInfoPBRec;
-
- begin
-
- with MyPB do
- begin
- ioNamePtr := @NextLaunch;
- ioVRefNum := vRefNum;
- ioFDirIndex := 0;
- ioDirID := 0;
- end; { with }
- FileError := PBGetCatInfo(@MyPB, false);
-
- pMyLaunch := @myLaunch;
- with pMyLaunch^ do
- begin
- pfName := @NextLaunch;
- param := 0;
- LC[0] := 'L';
- LC[1] := 'C';
- extBlockLen := 6;
- fFlags := myPB.ioFlFndrInfo.fdFlags;
- if MultiFinder then
- LaunchFlags := $C0000000 { set BOTH high bits for a sublaunch }
- else
- LaunchFlags := $00000000; { just launch, then quit }
- end; { with pMyLaunch^ }
- FileError := Launchit(pMyLaunch);
- end;
-
- { ------------------------------------------------------ }
-
- procedure HelloTabby;
-
- { This procedure looks for a Tabby launch.next file. If it's found, it }
- { extracts the events, which are comma delimited, saves the first one }
- { for the next launch and rewrites the file from event #2 to the last }
- { event. }
-
- { If it finds only one event, it kills the launch.next file. }
-
- { If there are no events, it returns the application name contained in }
- { STR 500 as STR255 NextLaunch, otherwise it uses NextLaunch to hold }
- { the first entry in the launch.next script. }
-
- { Before returning, it also checks that the NextLaunch application exists }
- { by trying to open it. If the open attempt fails, it returns NextLaunch }
- { as an empty string. }
-
- type
- HundredEvents = array[1..100] of string[32];
- ManyChars = packed array[1..3300] of char; { Can hold 100 32-length events, commas and one <CR> }
-
- var
- EventCounter, EventLimit, LNRefNum, LaunchCount: integer;
- LNChar: char;
- BBSByte: SignedByte;
- TheChars: ManyChars;
- Event: HundredEvents;
- Events, ThisEvent, VolName, TempString, BBSName: STR255;
- logicalEOF, Quantity, CharIndex: longint;
- CharCount, SetUpRef, SetUpCount: integer;
- fndrInfo: FInfo;
-
- begin
- FileError := GetVol(@VolName, vRefNum); { Get volume ref # for default volume }
- Events := '';
- for EventCounter := 1 to 100 do
- Event[EventCounter] := '';
- ThisEvent := '';
- LNChar := chr(255); { Dummy value so we can spot this first time through }
- NextLaunch := GetString(500)^^; { Get next launch string from resource }
- ReadConfig; { See if we're running MultiFinder }
- EventCounter := 1;
- FileError := FSOpen('launch.next', vRefNum, LNRefNum);
- FileError := GetEOF(LNRefNum, logicalEOF);
- if (logicalEOF > 0) and (FileError = NoErr) then
- begin
- FileError := SetFPos(LNRefNum, fsFromStart, 0);
- LaunchCount := 0;
- while (LNChar <> chr(13)) & (LaunchCount <= logicalEOF) do
- begin
- while (LNChar <> ',') & (LNChar <> chr(13)) & (LaunchCount <= logicalEOF) do
- begin
- if (LNChar <> chr(255)) then
- ThisEvent := concat(ThisEvent, LNChar);
- LaunchCount := LaunchCount + 1;
- Quantity := 1;
- FileError := FSRead(LNRefNum, Quantity, @LNChar);
- LNChar := chr(ord(LNChar) div 256);
- end; { (LNChar <> ',') & (LNChar <> chr(15)) & (LaunchCount <= logicalEOF) }
- Event[EventCounter] := ThisEvent;
- EventCounter := EventCounter + 1;
- ThisEvent := '';
- LNChar := chr(255)
- end; { (LNChar <> chr(13)) & (LaunchCount <= logicalEOF) }
- FileError := FSClose(LNRefNum);
- FileError := FSDelete('launch.next', vRefNum);
- EventLimit := (EventCounter - 2);
- if EventLimit > 1 then
- begin
- FileError := Create('launch.next', vRefNum, 'QUED', 'TEXT');
- FileError := FSOpen('launch.next', vRefNum, LNRefNum);
- FileError := SetFPos(LNRefNum, fsFromStart, 0);
- CharIndex := 0;
- for EventCounter := 2 to EventLimit do
- begin
- TempString := Event[EventCounter];
- for CharCount := 1 to length(TempString) do
- TheChars[CharIndex + CharCount] := TempString[CharCount];
- CharIndex := CharIndex + length(TempString) + 1;
- if EventCounter <> EventLimit then
- TheChars[CharIndex] := ','
- else
- TheChars[CharIndex] := ENDLINE;
- end; {Counter loop}
- FileError := FSWrite(LNRefNum, CharIndex, @TheChars);
- FileError := FSClose(LNRefNum);
- FileError := FlushVol(@volName, vRefNum);
- end; {EventLimit > 1}
- if EventLimit > 0 then
- NextLaunch := Event[1];
- TempString := NextLaunch;
- UprString(TempString, false);
- if TempString = 'BBS' then
- begin
- FileError := FSOpen('Tabby:Tabby Setup', vRefNum, SetupRef);
- if FileError = NoErr then
- FileError := GetEOF(SetupRef, logicalEOF);
- if (logicalEOF > 0) & (FileError = NoErr) then
- begin
- FileError := SetFPos(SetupRef, fsFromStart, 0);
- BBSName := '';
- Quantity := 1;
- BBSByte := 0;
- SetupCount := 0;
- while (BBSByte <> 13) & (SetupCount <= logicalEOF) do
- begin
- FileError := FSRead(LNRefNum, Quantity, @BBSByte);
- if BBSByte <> 13 then
- BBSName := concat(BBSName, chr(BBSByte));
- end; { while (BBSByte <> 13) & (SetupCount <= logicalEOF) }
- FileError := FSClose(SetupRef);
- NextLaunch := BBSName;
- end { if logicalEOF > 0 for 'Tabby:Tabby Setup' }
- end; { if TempString = 'BBS' }
- end { if logicalEOF > 0 for 'launch.next' }
- else
- begin
- FileError := FSClose(LNRefNum);
- FileError := FSDelete('launch.next', vRefNum)
- end;
- FileError := GetFInfo(NextLaunch, vRefNum, fndrInfo); { Is it an application? }
- if (FileError <> noErr) | (fndrInfo.fdType <> 'APPL') then
- NextLaunch := ''
- end; { HelloTabby procedure }
- end. { Unit }